import json

def dummy_data(data_path=None):
    with open('machine_health_api_response.json', 'r', encoding='utf-8') as f:
        machine_health_api_response = f.read()
    data = json.loads(machine_health_api_response)

    from multi_task_test import multi_task_test
    from config import CONFIG
    MULTI_TASK_MODEL_PATH = CONFIG['MULTI_TASK_MODEL_PATH']
    if not data_path:
        MULTI_TASK_DATA_PATH = CONFIG['MULTI_TASK_DATA_PATH']
    else:
        MULTI_TASK_DATA_PATH = data_path
    print ('use data file : ', MULTI_TASK_DATA_PATH)
    multi_task_result = multi_task_test(MULTI_TASK_MODEL_PATH, MULTI_TASK_DATA_PATH)
    print ('multi_task_result = ', multi_task_result)

    components = data['data']['status_monitoring']['components'] # 所有的设备状态列表

    # 液压泵
    component = next((item for item in components if item['name'] == '液压泵'), None)
    status_code = multi_task_result[0][0]
    status_text_list = ['无泄漏', '轻微泄漏', '严重泄漏']
    status_text = status_text_list[status_code]
    component['status_code'] = status_code
    component['status'] = status_text

    # 伺服作动器
    component = next((item for item in components if item['name'] == '伺服作动器'), None)
    status_code = multi_task_result[1][0]
    status_text_list = ['推力正常', '推力略降低', '推力降低', '推力严重降低']
    status_text = status_text_list[status_code]
    component['status_code'] = status_code
    component['status'] = status_text

    # 冷却器
    component = next((item for item in components if item['name'] == '冷却器'), None)
    status_code = multi_task_result[2][0]
    status_text_list = ['效率正常', '效率降低', '接近失效']
    status_text = status_text_list[status_code]
    component['status_code'] = status_code
    component['status'] = status_text

    # 电液伺服阀
    component = next((item for item in components if item['name'] == '电液伺服阀'), None)
    status_code = multi_task_result[3][0]
    status_text_list = ['切换正常', '切换轻微滞后', '切换严重滞后', '切换失灵']
    status_text = status_text_list[status_code]
    component['status_code'] = status_code
    component['status'] = status_text

    # print ('component = ', component)

    # print ('components = ', components)
    return data